package com.example.administrator.about_huanxin;

import android.support.v4.app.Fragment;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/3/8.
 */
public final class FragmentFactory {

    public FragmentFactory() {
    }

    private static Map<Class,Fragment> map = new HashMap<>();

    public static synchronized Fragment getInstance(Class<? extends Fragment> clazz){
        Fragment fragment = map.get(clazz);
        if(fragment == null){
            try {
                fragment = clazz.newInstance();
                map.put(clazz,fragment);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return fragment;
    }
}
